問題の説明
母音 + 周囲の子音で文字列を分割 (split string at vowel + surrounding consonants)
コーディングは初めてで、これが初めての試みです。音声言語から単語を音節に分割したい。
音声言語の単語から音節を作成する規則:
最初の母音まですべての子音を考慮し、その母音を考慮します。
例:
ma ‑ ri‑ a
a ‑ le ‑ ksa ‑ nda ‑ r
ここまで来ました:
word = 'aleksandar'
vowels = ['a','e','i','o','u']
consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
for vowel in vowels:
if vowels in word:
index_1 = int(word.index(vowel)) ‑ 1
index_2 = int(word.index(vowel)) + 1
print(word[index_1:index_2])
else:
print(consonants)
IDK 何が悪いのか、助けてください! 前もって感謝します:)
リファレンスソリューション
方法 1:
i have changed your code little bit and it works perfectly!!!
word = 'aleksandar'
word = list(word)
vowels = ['a','e','i','o','u']
s = ""
syllables = [ ]
for i in range(len(word)):
if word[i] not in vowels:
s = s + word[i]
else:
s = s + word[i]
syllables.append(s)
s = ""
print(syllables)
and the output is :
['a', 'le', 'ksa', 'nda']
方法 2:
This should solve your problem
word = 'aleksandar'
vowels = ['a','e','i','o','u']
new_word = ""
for letter in word:
if letter in vowels:
new_word += letter + "‑"
else:
new_word += letter
print(new_word)
(by HR_BO、Srikrishna K、Sagar Lama)